package com.cxm.homework7.aspectJ.anno;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;



@Aspect
@Component
public class UserAspect {
    @Pointcut("execution(* com.cxm.homework7.aspectJ.anno.*.*(..))")
    private void myAspect(){};

    @Before("myAspect()")
    public void before(JoinPoint joinPoint){
        System.out.println("前置通知：" + joinPoint.getSignature().getName());
    }

    @AfterReturning("myAspect()")
    public void afterRe(JoinPoint joinPoint){
        System.out.println("后置通知：" + joinPoint.getSignature().getName());
    }

    @Around("myAspect()")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("环绕通知-前：" + proceedingJoinPoint.getSignature().getName());
        Object obj = proceedingJoinPoint.proceed();
        System.out.println("环绕通知-后：" + proceedingJoinPoint.getSignature().getName());
        return obj;
    }

    @After("myAspect()")
    public void after(JoinPoint joinPoint){
        System.out.println("最终通知：" + joinPoint.getSignature().getName());
    }

    @AfterThrowing(value = "myAspect()",throwing = "e")
    public void throwing(JoinPoint joinPoint,Throwable e){
        System.out.println("异常通知：" + joinPoint.getSignature().getName());
        System.out.println(e.getMessage());
    }
}
